<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isAll">
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      v-model="value"
      placeholder="输入任务名称-回车确认"
      @keyup.enter="enterFn"
      autofocus
    />
  </header>
</template>

<script>
export default {
  data() {
    return {
      value: '',
    }
  },
  computed: {
    isAll: {
      set(val) {
        this.$store.state.getList.list.forEach(item => item.value = val)
      },
      get() {
        return this.$store.state.getList.list.every(item => item.value)
      }
    }
  },
  methods: {
    enterFn() {
      this.$store.commit('getList/addList', {
        name: this.value,
        value: false
      })
      this.value = ''
    }
  }
}
</script>
